package com.example.payserver1040.feignclient;

import com.example.springcloudusercommon.entity.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 温伟雄
 * @Date: 2021/10/13/9:36
 * @Description:
 */
@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    @Override
    public UserFeignClient create(Throwable throwable) {
        //返回UserFeignClient接口的实例
        return new UserFeignClient() {
            @Override
            public User getById(Long id) {
                //把异常信息打印到控制台
                throwable.printStackTrace();
                //真正的托底方法 ， 这里的数据是托底数据
                return new User(-1L,"无此用户","用户服务不可用");
            }
        };
    }
}
